import { Redirect } from 'umi';
import { getCookie } from '@/utils/cookie';
import {useModel} from "@@/plugin-model/useModel";
import {history} from "@@/core/history";
// @ts-ignore
const Auth = (props : any) => {
    const { initialState } = useModel('@@initialState');
    const _token = getCookie('Aircas-TOKEN');
    // @ts-ignore
    if(_token && initialState.currentUser){
        return(
            <div>
                {props.children}
            </div>
        )
    }
    else{
        const { query = {},pathname } = history.location;
        const { redirect } = query;
        return <Redirect to={`/user/login?redirect=${redirect||pathname}`}/>
    }

}

export default Auth;
